//
//  GQHServiceWebController.m
//  Xanthium
//
//  Created by GuanQinghao on 11/02/2018.
//  Copyright © 2018 GuanQinghao. All rights reserved.
//

#import "GQHServiceWebController.h"
#import "GQHHeader.h"
#import <WebKit/WebKit.h>

@interface GQHServiceWebController () <WKUIDelegate,WKNavigationDelegate>

@end


@implementation GQHServiceWebController

#pragma mark --Lifecycle
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self loadWebView];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    self.qh_titleLabel.text = self.qh_navCaptionString;
    self.qh_rightButton.hidden = YES;
}

- (void)loadWebView {
    
    WKWebView *webView = [[WKWebView alloc] init];
    webView.UIDelegate = self;
    webView.navigationDelegate = self;
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.qh_URLString]]];
    [self.view addSubview:webView];
    [webView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.view.qh_statusBarHeight + self.view.qh_navigationBarHeight);
        make.left.and.right.mas_equalTo(self.view);
        make.bottom.mas_equalTo(self.view);
    }];
}

#pragma mark ---WKNavigationDelegate
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation {
    
    [self qh_loadLoadingView];
}

- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
    
    [self qh_removedLoadingView];
}

- (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error {
    
}

@end
